﻿using SixLabors.ImageSharp;

namespace MicroCloud.Identity.Datas
{
    #region "图片名称"
    /// <summary>
    /// 图片名称
    /// </summary>
    public enum ImageName
    {
        /// <summary>
        /// cat_default
        /// </summary>
        CatAvatar = 100,
        /// <summary>
        /// user_default
        /// </summary>
        UserAvatat = 101,
        /// <summary>
        /// org_default
        /// </summary>
        OrgLogo = 200,
        /// <summary>
        /// logo_default
        /// </summary>
        LogoDefault = 201,
        /// <summary>
        /// logo108_default
        /// </summary>
        Logo108Default = 202,
    }
    #endregion

    #region "静态资源帮助类"
    /// <summary>
    /// 静态资源帮助类
    /// </summary>
    public static class StaticHelper
    {
        #region "常量"
        #region "程序集内图片资源目录"
        /// <summary>
        /// 程序集内图片资源目录
        /// </summary>
        private const string ImageAssemblyDirectory = @"MicroCloud.Identity.Datas.Static.Image";
        #endregion

        #endregion

        #region "静态方法"
        #region "获取指定图片资源"
        /// <summary>
        /// 获取指定图片资源
        /// </summary>
        /// <param name="imgName"></param>
        /// <returns></returns>
        public static Image GetImage(ImageName imgName)
        {
            var imgNameStr = "";
            switch (imgName)
            {
                case ImageName.CatAvatar:
                    imgNameStr = $"{ImageAssemblyDirectory}.Avatar.cat_default.png";
                    break;
                case ImageName.UserAvatat:
                    imgNameStr = $"{ImageAssemblyDirectory}.Avatar.user_default.png";
                    break;
                case ImageName.OrgLogo:
                    imgNameStr = $"{ImageAssemblyDirectory}.Logo.org_default.png";
                    break;
                case ImageName.LogoDefault:
                    imgNameStr = $"{ImageAssemblyDirectory}.Logo.logo_default.png";
                    break;
                case ImageName.Logo108Default:
                    imgNameStr = $"{ImageAssemblyDirectory}.Logo.logo108_default.png";
                    break;
            }
            if (!imgNameStr.IsMissing())
            {
                var imgStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(imgNameStr);
                Image image = Image.Load(imgStream);

                return image;
            }

            return null;
        }
        #endregion
        #region "获取指定图片资源的Base64字符串"
        /// <summary>
        /// 获取指定图片资源的Base64字符串
        /// </summary>
        /// <param name="imgName"></param>
        /// <returns></returns>
        public static string GetImgBase64String(ImageName imgName)
        {
            var image = GetImage(imgName);
            if (image != null)
            {
                return image.ToBase64String();
            }
            return null;
        }
        #endregion

        #endregion

    }
    #endregion

}
